<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

  <head>
    <title>org.brophy.js Library Demos</title>
    <script type="text/javascript">MochiKit = {__export__: false};</script>
    <script type="text/javascript" src="../MochiKit/MochiKit.js"></script>
    <script type="text/javascript" src="../org/brophy/js/constant.js"></script>
    <script type="text/javascript" src="../org/brophy/js/util.js"></script>
    <script type="text/javascript" src="../org/brophy/js/ajax.js"></script>
    <script type="text/javascript" src="../org/brophy/js/array.js"></script>
    <script type="text/javascript" src="../org/brophy/js/select.js"></script>
    <script type="text/javascript" src="../org/brophy/js/event.js"></script>
    <script type="text/javascript" src="./org.brophy.js.demo.js"></script>
    <link rel="stylesheet" type="text/css" href="../org/brophy/css/org.brophy.js.css"/>
    <link rel="stylesheet" type="text/css" href="org.brophy.js.demo.css"/>

    <script type="text/javascript">
    //<![CDATA[
    
      // Global namespace to store all demo functions
      obj = {};

      window.onload = function()
      {
        org.brophy.js.demo.drawPageHeader("array");

        var jsCode, htmlCode, instructions;
        
        /********************************************
         * org.brophy.js.array.indexOf 
         ********************************************/ 
        jsCode = 
          "var indexOfArr = [1, 3, 5, 6, 8, 9];                          \n\n" + 
          "obj.testIndexOf = function()                                  \n" + 
          "{                                                             \n" +
          "  var value = document.getElementById('indexOfInput').value;  \n" +
          "  alert('The index is: ' +                                    \n" + 
          "        org.brophy.js.array.indexOf(indexOfArr,value));       \n" +
          "}                                                             \n";
  
        htmlCode = 
          "<input type='text' name='indexOfInput'                        \n" + 
          "       id='indexOfInput' size='3'/>                           \n" + 
          "<input type='button' value='Get the index?'                   \n" + 
          "       onclick='obj.testIndexOf();'/>                         \n";
             
        instructions = 
          "Enter any number in the input box and press the button.  You  " + 
          "will be alerted of the index of the number you entered in the " + 
          "following array: [1, 3, 5, 6, 8, 9]";
   
        org.brophy.js.demo.drawDemoSection(
                             "org.brophy.js.array.indexOf",
                             "demo_obj_array_indexOf",
                             htmlCode,
                             jsCode,
                             instructions);
        
  
  
        /********************************************
         * org.brophy.js.array.sortArrayOfObjects 
         ********************************************/ 
        htmlCode = "<div>                                              \n" + 
                   "  <ul id='sortArrayUL'>                            \n" + 
                   "    <!-- The results will be added here... -->     \n" + 
                   "  </ul>                                            \n" + 
                   "</div>                                             \n";
             
        jsCode = 
          "// Simple function to print out an array below              \n" + 
          "obj.printArray = function(label,arr)                        \n" + 
          "{                                                           \n" +
          "  MochiKit.DOM.appendChildNodes(                            \n" + 
          "     MochiKit.DOM.getElement('sortArrayUL'),                \n" + 
          "     MochiKit.DOM.LI(label + ' = ' +                        \n" + 
          "                     MochiKit.Base.serializeJSON(arr)));    \n" +
          "}                                                           \n" +
          "                                                            \n" +
          "/*********************************************              \n" + 
          " * Using the basic version of the function                  \n" + 
          " *********************************************/             \n" + 
          "var array1 = [1, -3, 15, -4, 5, 2, 7, 3, 8];                \n" + 
          "array1 = org.brophy.js.array.sortArrayOfObjects(array1);    \n" + 
          "obj.printArray('array1', array1);                           \n" +
          "                                                            \n" +
          "/*********************************************              \n" + 
          " * Using a different comparison function                    \n" + 
          " * (to sort in reverse order)                               \n" + 
          " *********************************************/             \n" + 
          "var myCompare = function(a,b)                               \n" + 
          "  { return MochiKit.Base.compare(b,a); };                   \n" + 
          "var array2 = [1, -3, 15, -4, 5, 2, 7, 3, 8];                \n" + 
          "array2 = org.brophy.js.array.sortArrayOfObjects(array2, null, myCompare); \n" + 
          "obj.printArray('array2', array2);                           \n" +
          "                                                            \n" +
          "/*********************************************              \n" + 
          " * Sorting an array of objects                              \n" + 
          " *********************************************/             \n" + 
          "var array3 = [ { 'a' : 1 },                                 \n" + 
          "               { 'a' : -3 },                                \n" +  
          "               { 'a' : 15 },                                \n" +  
          "               { 'a' : -4 },                                \n" +  
          "               { 'a' : 5 },                                 \n" +  
          "               { 'a' : 2 },                                 \n" +  
          "               { 'a' : 7 },                                 \n" +  
          "               { 'a' : 3 },                                 \n" +  
          "               { 'a' : 8 } ];                               \n" +  
          "                                                            \n" +
          "array3 = org.brophy.js.array.sortArrayOfObjects(array3, 'a'); \n" + 
          "obj.printArray('array3', array3);                           \n" +
          "                                                            \n" +
          "/*********************************************              \n" + 
          " * Ignoring the first few elements                          \n" + 
          " *********************************************/             \n" + 
          "var array4 = [1, -3, 15, -4, 5, 2, 7, 3, 8];                \n" + 
          "array4 = org.brophy.js.array.sortArrayOfObjects(array4, null, null, 2);\n" + 
          "obj.printArray('array4', array4);                           \n" +
          "                                                            \n" +
          "\n";
  
        instructions = 
          "Below are the results from the above JavaScript examples:";
   
        org.brophy.js.demo.drawDemoSection(
                             "org.brophy.js.array.sortArrayOfObjects",
                             "demo_obj_array_sortArrayOfObjects",
                             htmlCode,
                             jsCode,
                             instructions);
        
  
  
        /********************************************
         * org.brophy.js.array.sortArray
         ********************************************/ 
        htmlCode = "<div>                                              \n" + 
                   "  <ul id='sortArrayUL2'>                           \n" + 
                   "    <!-- The results will be added here... -->     \n" + 
                   "  </ul>                                            \n" + 
                   "</div>                                             \n";
             
        jsCode = 
          "obj.printArray2 = function(label,arr)                       \n" + 
          "{                                                           \n" +
          "  MochiKit.DOM.appendChildNodes(                            \n" + 
          "     MochiKit.DOM.getElement('sortArrayUL2'),               \n" + 
          "     MochiKit.DOM.LI(label + ' = ' +                        \n" + 
          "                     MochiKit.Base.serializeJSON(arr)));    \n" +
          "}                                                           \n" +
          "                                                            \n" +
          "/*********************************************              \n" + 
          " * Using the basic version of the function                  \n" + 
          " *********************************************/             \n" + 
          "var array1 = [1, -3, 15, -4, 5, 2, 7, 3, 8];                \n" + 
          "array1 = org.brophy.js.array.sortArray(array1);             \n" + 
          "obj.printArray2('array1', array1);                          \n" +
          "                                                            \n" +
          "/*********************************************              \n" + 
          " * Using a different comparison function                    \n" + 
          " * (to sort in reverse order)                               \n" + 
          " *********************************************/             \n" + 
          "var myCompare = function(a,b)                               \n" + 
          "  { return MochiKit.Base.compare(b,a); };                   \n" + 
          "var array2 = [1, -3, 15, -4, 5, 2, 7, 3, 8];                \n" + 
          "array2 = org.brophy.js.array.sortArray(array2, myCompare);  \n" + 
          "obj.printArray2('array2', array2);                          \n" +
          "                                                            \n" +
          "\n";
  
        instructions = 
          "Below are the results from the above JavaScript examples:";
   
        org.brophy.js.demo.drawDemoSection(
                             "org.brophy.js.array.sortArray",
                             "demo_obj_array_sortArray",
                             htmlCode,
                             jsCode,
                             instructions);
      }
  
    //]]>
    </script>
  
  </head> 
  
  <body>
  </body>
  
</html>
  
  
  
